package com.wash.shoes.util;

import com.wash.shoes.entity.ShoeRackGridPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lijianguo
 * @Date 28/09/2024 9:43
 * 请输入类的简介
 **/
public class GridShareUtil {

    /**
     * @author lijianguo
     * @Date 28/09/2024
     * 这个是连续的分配算法
     **/
    public static List<ShoeRackGridPo> shareGridContinuous(List<ShoeRackGridPo> shoeRackGridPoList, Integer needNum) {

        List<ShoeRackGridPo> totalGridPoList = new ArrayList<>();
        Integer currentNum = null;
        // 如果已经够了就返回
        for (ShoeRackGridPo shoeRackGridPo : shoeRackGridPoList) {
            if (totalGridPoList.size() == needNum) {
                return totalGridPoList;
            }
            if (currentNum == null) {
                totalGridPoList.add(shoeRackGridPo);
                currentNum = shoeRackGridPo.getSortNum();
                // 相邻的格子
            } else if (currentNum - shoeRackGridPo.getSortNum() == 1) {
                totalGridPoList.add(shoeRackGridPo);
                currentNum = shoeRackGridPo.getSortNum();
                if (totalGridPoList.size() == needNum) {
                    return totalGridPoList;
                }
            } else {
                totalGridPoList.clear();
                totalGridPoList.add(shoeRackGridPo);
                currentNum = shoeRackGridPo.getSortNum();
            }
        }
        return new ArrayList<>();
    }


}
